<?php
	$validation_rules = array(
		"age" => array(
            'number' => true
		),
		"real_last_name" => array(
            'maxlength' => 255
		),
		"real_first_name" => array(
            'maxlength' => 255
		),
		"other_name" => array(
            'maxlength' => 255
		),
		"nickname" => array(
            'maxlength' => 255
		),
		"last_name" => array(
            'maxlength' => 255
		),
		"first_name" => array(
            'maxlength' => 255
		),
		"occupation" => array(
            'maxlength' => 255
		)
	);
?>

<?php
    if ($act==='view') {
        FormHelper::setReadonly(true);
        $validation_rules = array();
    }
    
$from = isset($data['from']) ? $data['from'] : '';
$episode_id = isset($data['episode_id']) ? $data['episode_id'] : '';
$cast = isset($data['cast']) ? $data['cast'] : array();
$programme = isset($data['programme']) ? $data['programme'] : array();
$folder_list = isset($data['folder_list']) ? $data['folder_list'] : array();
$tag_list = isset($data['tag_list']) ? $data['tag_list'] : array();
$allow_tag = isset($data['allow_tag']) ? $data['allow_tag'] : array();
$form_action = ($act === 'view') ? "cast_switch.html" : "cast_step2.html";
$alphabetic = ($cast->language_id == 2) ? "" : "checked";
$publish = isset($data['unpublish']) ? $data['unpublish'] : 0;
$language_id_cn = language::getLanguageId(AC::LANGUAGE_ZH);
$language_id_en = language::getLanguageId(AC::LANGUAGE_EN);
?>

<div id="cast" class="mod ui-widget-content ui-helper-clearfix ui-corner-all <?php echo $act; ?>">

    <div class="hd ui-widget-header ui-helper-clearfix ui-corner-all"><h2><?php echo $act_text; ?> Cast</h2></div>

    <div class="bd">
    <?php FormHelper::StartForm('ane', AC::PDES_BASE_URL.$form_action) ?>
        <?php FormHelper::HiddenField('is_folder_update', '0') ?>
        <?php FormHelper::ErrorMessages($errors) ?>
        <fieldset class="ui-widget-content">
    		<legend class="ui-widget-header">Programme Information</legend>
    		<?php FormHelper::ProtectedField($programme->id, 'Programme ID');?>
            <?php FormHelper::ProtectedField($cast->id, 'Cast ID');?>
    		<?php FormHelper::HiddenField('programme_id', $cast->programme_id) ?>
    		<?php FormHelper::HiddenField('episode_id', $episode_id) ?>
            <?php 
				FormHelper::ProtectedField($programme->zh_programme_name,
										   "Programme Title (Chinese)");
				FormHelper::ProtectedField($programme->en_programme_name, 
										   "Programme Title (English)");
			?> 
        </fieldset>
        
    	<fieldset class="ui-widget-content">
    		<legend class="ui-widget-header">Cast Basic Information</legend>
    		<?php FormHelper::HiddenField('id', $cast->id) ?>
    		<?php FormHelper::HiddenField('folders', $cast->folders) ?>
    		<?php FormHelper::HiddenField('available_tag_types', $cast->available_tag_types) ?>
			<?php FormHelper::HiddenField('tags', $cast->tags) ?>
    		<?php FormHelper::HiddenField('cast_role_id', $cast->cast_role_id) ?>
    		<?php FormHelper::HiddenField('status', $cast->status) ?>
    		<?php FormHelper::HiddenField('from', $from) ?>
			<?php FormHelper::HiddenField('created_at', $cast->created_at) ?>
			<?php FormHelper::HiddenField('created_by', $cast->created_by) ?>
			<?php FormHelper::HiddenField('modified_at', $cast->modified_at) ?>
			<?php FormHelper::HiddenField('modified_by', $cast->modified_by) ?>

			<?php 
				FormHelper::FirstLastName(
					array(
						'first'	=> 	array(
										'name' 	=> 'real_first_name_cn',
										'value'	=> $cast->cast_language[$language_id_cn]['real_first_name']
								  	),
						'last'	=> 	array(
										'name'	=> 'real_last_name_cn',
										'value'	=> $cast->cast_language[$language_id_cn]['real_last_name']
									)
					), 
					"Artiste Name (Chinese)" , 
					true
				);
				
FormHelper::FirstLastName(array(
    'first'=>array(
        'name'=>'real_first_name_en',
        'value'=> $cast->cast_language[$language_id_en]['real_first_name']),
    'last'=>array(
            'name'=>'real_last_name_en',
            'value'=> $cast->cast_language[$language_id_en]['real_last_name'])), 
    "Artiste Name (English)" , false); ?>
			<?php 
				FormHelper::TextField('other_name_cn', $cast->cast_language[$language_id_cn]['other_name'], 
									  'Artiste Other Name (Chinese)');
				FormHelper::TextField('other_name_en', $cast->cast_language[$language_id_en]['other_name'], 
									  'Artiste Other Name (English)');
			?>
            <?php FormHelper::FirstLastName(array(
                'last'=>array(
                    'name'=>'last_name_cn',
                    'value'=> $cast->cast_language[$language_id_cn]['last_name']), 
                'first'=>array(
                        'name'=>'first_name_cn',
                        'value'=>$cast->cast_language[$language_id_cn]['first_name'])), 
                "Cast Name (Chinese)" , true); ?>
            <?php FormHelper::FirstLastName(array(
                'last'=>array(
                    'name'=>'last_name_en',
                    'value'=> $cast->cast_language[$language_id_en]['last_name']),
                'first'=>array(
                    'name'=>'first_name_en',
                    'value'=> $cast->cast_language[$language_id_en]['first_name'])), 
            "Cast Name (English)" , false); ?>

            <?php                                                                                                            
				FormHelper::TextField('nickname_cn', 
									  $cast->cast_language[$language_id_cn]['nickname'],
									  'Cast Nickname (Chinese)');
				FormHelper::TextField('nickname_en', 
									  $cast->cast_language[$language_id_en]['nickname'],
									  'Cast Nickname (English)');
				FormHelper::ProtectedField($cast->role_name, "Cast Role ", true);
				FormHelper::RadioButton('gender', array('M'=>'Male','F'=>'Female'), $cast->gender, 'Gender 性別');
				FormHelper::TextField('age', $cast->age, 'Age 年齡', '');
				FormHelper::TextField('occupation_cn', 
									  $cast->cast_language[$language_id_cn]['occupation'],
									  'Occupation (Chinese)');
				FormHelper::TextField('occupation_en', 
									  $cast->cast_language[$language_id_en]['occupation'],
									  'Occupation (English)');
                
                $personality_cn_encode = $cast->cast_language[$language_id_cn]['personality'];

                $personality_en_encode = $cast->cast_language[$language_id_en]['personality'];
                
                $profile_cn_encode = $cast->cast_language[$language_id_cn]['profile'];

                $profile_en_encode = $cast->cast_language[$language_id_en]['profile'];
               
                $history_cn_encode = $cast->cast_language[$language_id_cn]['history'];
                
                $history_en_encode =$cast->cast_language[$language_id_en]['history'];
               
                FormHelper::TextArea('personality_cn', 
									  $personality_cn_encode,
									 'Personality (Chinese)');
				FormHelper::TextArea('personality_en', 
									 $personality_en_encode,
									 'Personality (English)');
				FormHelper::TextArea('profile_cn', 
								     $profile_cn_encode,	
									 'Profile (Chinese)');
				FormHelper::TextArea('profile_en', 
                                     $profile_en_encode,
									 'Profile (English)');
				FormHelper::TextArea('history_cn', 
									$history_cn_encode,
									 'History (Chinese)');
				FormHelper::TextArea('history_en', 
                                    $history_en_encode,
									 'History (English)');
			?> 
    	</fieldset>

        <a id="anchor-image"></a>
        <fieldset class="ui-widget-content">
            <legend class="ui-widget-header">Images</legend>
<?php if($act != 'view'){ ?>        
			<div class="ui-helper-clearfix folder-manager-box">
				<a href="#image-cast-<?php echo $cast->id;?>" class="btn ui-state-default ui-corner-all folder-manager-btn" title="Manage Folders">Manage Folders</a>
			</div>
<?php } ?>
<?php
if (isset($folder_list['folders']) && (count($folder_list['folders']) > 0) ) {
	FormHelper::RedCallers('forders', $folder_list);
}
?>
        </fieldset>
    
        <fieldset class="ui-widget-content">
            <legend class="ui-widget-header">Record Status and Access Log</legend>
        	    <?php FormHelper::ProtectedField(AC::$op_status[$cast->status], 'Record Status', true) ?>
			    <?php FormHelper::ProtectedField($cast->created_by, 'Created By') ?>
        	    <?php FormHelper::ProtectedField($cast->created_at, 'Created At') ?>
         	    <?php FormHelper::ProtectedField($cast->modified_by, 'Modified By') ?>       	
        	    <?php FormHelper::ProtectedField($cast->modified_at, 'Modified At') ?>
        </fieldset>

        <?php FormHelper::DisplayPublishLog($data['publishLog']); ?>
        <span class="buttons">
        <?php 
            switch ($act) {
                case 'add':
                    ($step == 2) ?  FormHelper::SubmitButton('update', 'Update') : FormHelper::SubmitButton('create', 'Create');  
                    FormHelper::ResetButton('reset', 'Reset');
					($step == 2) ? FormHelper::Button('top', 'Top') : "";
                break;
                case 'edit':
                    FormHelper::SubmitButton('update', 'Update');
                    FormHelper::ResetButton('reset', 'Reset');
                	($from == '' || $from == 'task') ? FormHelper::Button('back', 'Back to list') : "";
					FormHelper::Button('top', 'Top');
                break;
                case 'view':
					/** modified by vanni for bug no:260 **/
                    if($publish ==1){
                        CommonUtils::showUnpublishButton($data, $data['_g']);
					}else{
						if($cast->status == AC::STATUS_DELETED){
							FormHelper::SubmitButton('recover', 'Recover');
						}else{
							FormHelper::SubmitButton('edit', 'Edit');
							# FormHelper::SubmitButton('clone', 'Clone');
                            CommonUtils::showDeleteButton($data['publishLog']);
						}
					}
					($from == '' || $from == 'task') ? FormHelper::Button('back', 'Back to list') : "";
					FormHelper::Button('top', 'Top');
                break;
            }
        ?>
    </span>
    <?php FormHelper::EndForm() ?>

    </div>

</div>

<script>
    TVB.Pdes.oValidation = {
        form: document.forms['ane'],
        rules: <?php echo json_encode($validation_rules); ?>
    };
</script>
